﻿var isStartMark = false;
var agName = "";
$(document).ready(function () {
    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"),
            { size: new GSize(640, 620) });

        var customUI = map.getDefaultUI();
        customUI.maptypes.hybrid = false;
        map.setUI(customUI);

        GEvent.addListener(map, "click", function (overlay, latlng) {
            if (isStartMark) {
                AddMark(latlng, map);
                SetDate(latlng, map.getZoom());
            }
        });

        if (mapMarkData != null) {
            map.setCenter(new GLatLng(mapMarkData.Latlng.Kd, mapMarkData.Latlng.Ga), mapMarkData.Zoom);
            agName = mapMarkData.AgencyName;
            AddMark(mapMarkData.Latlng, map);
        }
        else {
            map.setCenter(new GLatLng(39.91658293581713, 116.39328002929688), 11);
        }
    }
});

function AddMark(latlng, map) {
    if (latlng && agName != "") {
        map.clearOverlays();
        marker = new GMarker(latlng, { draggable: false });
        GEvent.addListener(marker, "mouseover", function () {
            marker.openInfoWindow(agName);
        });
        GEvent.addListener(marker, "mouseout", function () {
            marker.closeInfoWindow();
        });
        map.addOverlay(marker);
        marker.openInfoWindow(agName);
    }
}

function StartMark(aName) {
    agName = aName;
    document.getElementById("startMark").disabled = true;
    isStartMark = true;
}

function SetDate(latlng, zoom) {
    var date = { "Latlng": latlng, "Zoom": zoom, "AgencyName": agName };
    var myJSONText = JSON.stringify(date);
    document.getElementById("startMark").disabled = false;
    isStartMark = false;
    document.getElementById("mapMark").value = myJSONText;
    document.getElementById("submitButton").disabled = false;
}
